/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dorian.atomicuml.models;

import java.util.Locale;
import org.springframework.context.MessageSource;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

/**
 *
 * @author Ayden
 */
public class ProjectValidator implements Validator {
    
    private MessageSource messageSource;
    
    public ProjectValidator(MessageSource messageSource)
    {
        super();
        this.messageSource = messageSource;
    }
    
    @Override
    public boolean supports(Class<?> type) {
        return ProjectInfoData.class.isAssignableFrom(type);
    }

    @Override
    public void validate(Object o, Errors errors) {
 
        final String ERROR = messageSource.getMessage("project.errors.empty", null, Locale.FRENCH);
        
        ValidationUtils.rejectIfEmptyOrWhitespace(errors,
                                                  "projectTitle",
                                                  "errors.required",
                                                  new Object[] {"projectTitle"},
                                                  ERROR);

       ValidationUtils.rejectIfEmptyOrWhitespace(errors,
                                                 "projectDescription",
                                                 "errors.required",
                                                 new Object[] {"projectDescription"},
                                                 ERROR);
        
    }
    
}
